package com.xyb.controller;

import com.xyb.entity.CourseComment;
import com.xyb.entity.CourseCommentVo;
import com.xyb.entity.PageResult;
import com.xyb.entity.query.CourseCommentQuery;
import com.xyb.service.CommentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("comment")
public class CommentController {
    @Resource
    private CommentService commentService;

    /**
     * 对课程的一级评论
     * @param courseId
     * @param userId
     * @param courseComment
     * @return
     */
    @PostMapping("comment/{courseId}/{userId}")
    public String insertComment(@PathVariable("courseId") Long courseId, @PathVariable("userId") Long userId, @RequestBody CourseComment courseComment) {
        courseComment.setCourseId(courseId);
        courseComment.setUserId(userId);
        commentService.insertComment(courseComment);
        return "success";
    }

    /**
     * 查询我的评论
     * @param courseId
     * @param userId
     * @return
     */
    @GetMapping("/comment/my/{courseId}/{userId}")
    public List<CourseCommentVo> selectMyCommentListByCourseId(@PathVariable("courseId") Long courseId, @PathVariable("userId") Long userId){
        List<CourseCommentVo> list = commentService.selectMyCommentListByCourseId(courseId,userId);
        return list;
    }

    @GetMapping("/comment/{courseId}/{userId}")
    public PageResult<CourseCommentVo> selectCommentListByCourseId(@PathVariable("courseId") Long courseId, @PathVariable("userId") Long userId, CourseCommentQuery query){
        PageResult<CourseCommentVo> result = commentService.selectCommentListByCourseId(courseId,userId,query);
        return result;
    }



}
